home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / 7edit / source / svaetextutils.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.8 KB  |  109 lines

  1. /*
  2.     File:        SVAETextUtils.h
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Original version by Jon Lansdell and Nigel Humphreys.
  7.                 3.1 updates by Greg Sutton.
  8.  
  9.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                             7/20/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24.  
  25. #ifndef __SVAETEXTUTILS__
  26. #define __SVAETEXTUTILS__
  27.  
  28. #include "SVToken.h"
  29.  
  30. #include <TextEdit.h>
  31.  
  32. OSErr        PutStyledTextFromDescIntoTEHandle(const AEDesc *sourceTextDesc, TEHandle theHTE);
  33.  
  34. TEHandle    TEHandleFromWindow(WindowPtr theWindow);
  35. TEHandle    TEHandleFromTextToken(TextToken* aToken);
  36.  
  37. OSErr        GetInsertDescFromInsertHere(AEDesc* insertHereDesc,
  38.                                         AEDesc* insertDesc, DescType* insertType);
  39.                                         
  40. enum TokenWithinType
  41. {
  42.     kTokenBefore = 1, kTokenPartialBefore, kTokenWithin,
  43.     kTokenPartialAfter, kTokenAfter
  44. };
  45.  
  46. typedef enum TokenWithinType TokenWithinType;
  47.  
  48. TokenWithinType    TokenWithinToken(TextToken* container, TextToken* token, short* numPartial);
  49.  
  50.                 // Text from window routines
  51.  
  52. OSErr        TextTokenFromWindowToken(WindowToken* theWindowToken, TextToken* theTextToken);
  53. OSErr        TextTokenFromWindowDesc(AEDesc* windowDesc, TextToken* aToken);
  54. OSErr        TextDescFromWindowToken(WindowToken* theWindowToken, AEDesc* textDesc);
  55. OSErr        TextDescFromWindowDesc(AEDesc* windowDesc, AEDesc* textDesc);
  56.  
  57. typedef char chars[32001];
  58. typedef chars **charsHandle;
  59.  
  60.                 // Routines to count and get desccriptors of text
  61.  
  62. void         MoveToNonSpace(short *start, short limit, charsHandle myChars);
  63. void        MoveToSpace(short *start, short limit, charsHandle myChars);
  64. void        MoveToEndOfParagraph(short *start, short limit, charsHandle myChars);
  65.  
  66. OSErr        CountTextElements(TEHandle inTextHandle, short startAt,
  67.                                 short forHowManyChars, DescType elementType, short* result);
  68. OSErr        GetDescOfNthTextElement(short index, DescType elementType,
  69.                                         TextToken* containerToken, AEDesc* result);
  70.  
  71.                 // Routines to determine text token type
  72.  
  73. char        GetTEHChar(TEHandle aTEH, short offset);
  74.  
  75. Boolean        IsAtStart(TextToken* theToken);
  76. Boolean        IsAtEnd(TextToken* theToken);
  77. Boolean        IsWhiteSpace(short aChar);
  78. Boolean        IsParagraphDelimiter(short aChar);
  79. Boolean        IsContentsToken(TextToken* theToken);
  80. Boolean        IsParagraphToken(TextToken* theToken, short* start, short* end);
  81. Boolean        IsWordToken(TextToken* theToken, short* start, short* end);
  82.  
  83. DescType    GetTextTokenType(TextToken* theToken, short* start, short* end);
  84.  
  85. OSErr        MakeContentsSpecifier(TextToken* theToken, AEDesc* result);
  86. OSErr        MakeAbsoluteTextSpecifier(WindowPtr theWindow, DescType textType, long index, AEDesc* result);
  87. OSErr        MakeInsertionPointSpecifier(TextToken* theToken, AEDesc* result);
  88.  
  89. OSErr        GetIndexSpecifier(TextToken* theToken, DescType textType, long index, AEDesc* result);
  90.  
  91.                 // Call following routine to get a specifier for any given text token
  92.  
  93. OSErr        GetTextTokenObjectSpecifier(TextToken* theToken, AEDesc* result);
  94.  
  95. enum
  96. {
  97.     ETX = 0x03, // Enter key on keyboard or keypad
  98.     BS  = 0x08, // Backspace key on keyboard
  99.     HT  = 0x09, // Tab key on keyboard
  100.     LF    = 0x0A,    // Line feed character
  101.     CR  = 0x0D, // Return key on keyboard
  102.     ESC = 0x1B, // Clear key on keypad
  103.     FS  = 0x1C, // Left arrow key on keypad
  104.     GS  = 0x1D, // Right arrow key on keypad
  105.     RS  = 0x1E, // Up arrow key on keypad
  106.     US  = 0x1F  // Down arrow key on keypad
  107. };
  108.  
  109. #endif